<?php

/**
 * feed actions.
 *
 * @package    hacride
 * @subpackage feed
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class feedActions extends sfActions
{
  public function executeNews()
  {
    $feed = new sfAtom1Feed();

    $feed->setTitle('HACRIDE - news');
    $feed->setLink('http://www.hacride.com/');
    $feed->setAuthorEmail('hacride@hacride.com');
    $feed->setAuthorName('hacride');
    
    if ($this->getRequestParameter('sf_culture') 
    and $this->getRequestParameter('sf_culture') == 'fr' )
    {
      $this->getUser()->setCulture('fr');
    }
    else
    {
      $this->getUser()->setCulture('en');
      
    }

    $posts = PostPeer::getNewsByParams(
                            10,
                            $this->getUser()->getCulture(),
                            $this->getRequestParameter('year'),
                            $this->getRequestParameter('month'),
                            $this->getRequestParameter('day')
                            );
                            
    foreach ($posts as $post)
    {
      $item = new sfFeedItem();
      $item->setTitle($post->getTitle());
      $item->setLink($post->getPermalink());
      $item->setAuthorName($post->getGuardUser()->getDisplayname());
      $item->setPubdate($post->getCreatedAt('U'));
      $item->setUniqueId($post->getSlug());
      $item->setContent($post->getExcerpt().$post->getBody());
  
      $feed->addItem($item);
    }
  
    $this->feed = $feed;
                            
  }
  
  public function executeShows()
  {
    $feed = new sfAtom1Feed();

    $feed->setTitle('HACRIDE - upcoming shows');
    $feed->setLink('http://www.hacride.com/');
    $feed->setAuthorEmail('hacride@hacride.com');
    $feed->setAuthorName('hacride');
    
    $upcomingshows = ConcertPeer::getUpcomingShows(null, null, 'DESC');
    
    foreach ($upcomingshows as $show)
    {
      $item = new sfFeedItem();
      $item->setTitle($show->getLocation() . ' ' . $show->getPlayAt('m/d/Y'));
      $item->setLink('http://www.hacride.com/en/tour/');
      $item->setAuthorName('hacride');
      $item->setPubdate($show->getPlayAt('U'));
      $item->setUniqueId(md5($show->getLocation().$show->getPlayAt()));
      $item->setContent($show->getLocation().' '.$show->getSalle().' '.$show->getPlayAt('m/d/Y H:i'));
      
      $feed->addItem($item);
    }
  
    $this->feed = $feed;
  }
}
